home *** CD-ROM | disk | FTP | other *** search
/ Multimedia Jumpstart / Multimedia Microsoft Jumpstart Version 1.1a (Microsoft).BIN / develpmt / examples / infobrws / src / profile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  31.8 KB  |  1,062 lines

  1. //     (C) Copyright Microsoft Corp. 1991.  All rights reserved.
  2. //
  3. //     You have a royalty-free right to use, modify, reproduce and 
  4. //     distribute the Sample Files (and/or any modified version) in 
  5. //     any way you find useful, provided that you agree that 
  6. //     Microsoft has no warranty obligations or liability for any 
  7. //     Sample Application Files which are modified. 
  8.  
  9.  
  10. /****************************************************************************
  11.  
  12.     MODULE    : Profile.c
  13.  
  14.     PURPOSE   : This module is used to retrieve data from initialization files using GetProfileString.
  15.                 There are several ini file (playvfw.ini, button#.ini, morph.ini) all of which contain
  16.                 data pertaining to a different part of the program.  
  17.  
  18.     FUNCTIONS :  GetStuffFromIni
  19.                  GetPG2FromIni
  20.                  ReturnProfileError
  21.                  GetVidWinFromIni
  22.                  GetDirFromIni
  23.  
  24.  
  25.     COMMENTS  : 
  26.  
  27.     HISTORY   :  Created by Steven Molstad 6/1/93.
  28.  
  29. ****************************************************************************/
  30.  
  31. #include "windows.h"
  32. #include <stdlib.h>
  33. #include "playvfw.h"
  34. #include "proto.h"
  35. #include "mmsystem.h"
  36. #include <digitalv.h>
  37. #include <stdio.h>
  38. #include <time.h>
  39.  
  40. /****************************************************************************
  41.  
  42.     FUNCTION  : GetStuffFromIni(LPDEVICESTRUCT,int,LPSTR)
  43.  
  44.     PURPOSE   : This function retrieves information from the playvfw.ini file.  This information pertains
  45.                 to Buttons 1-6 of the first page and the initial screens VFW button.  The infomation retrieved
  46.                 is the AVI file, wave file, position of the button, whether to play the video or audio.  
  47.                 This function also opens the wave file and the AVI file.
  48.     
  49.     COMMENTS  : 
  50.  
  51.     HISTORY   : Created by Steven Molstad 6/15/93
  52.  
  53. ****************************************************************************/ 
  54.  
  55. BOOL FAR PASCAL GetStuffFromIni(lpDevice,nButton,lpPoints)
  56. LPDEVICESTRUCT lpDevice;
  57. int nButton;
  58. LPRECT lpPoints;
  59.  
  60. {
  61.      HANDLE hBuffer;
  62.      LPSTR lpBuffer;
  63.  
  64.      HANDLE hSection;
  65.      LPSTR lpSection;
  66.  
  67.      HANDLE hFileName;
  68.      LPSTR lpFileName;
  69.  
  70.      HANDLE hEntry;
  71.      LPSTR lpEntry;
  72.  
  73.      HANDLE hAlias;
  74.      LPSTR  lpAlias;
  75.  
  76.      HANDLE hExeName;
  77.      LPSTR lpExeName; 
  78.      
  79.      HANDLE hExtension;
  80.      LPSTR lpExtension;  
  81.      
  82.      HANDLE hNewFile;
  83.      LPSTR lpNewFile;
  84.  
  85.      int  nSize;
  86.      int nBytes;
  87.      int nAviFile;
  88.      int nAudioFile;  
  89.     
  90.     
  91.      // allocate memory for the different buffers that will be used to get the profile strings from the ini
  92.      // files.
  93.            
  94.      hBuffer=GlobalAlloc(GHND,80);
  95.      hSection=GlobalAlloc(GHND,10);
  96.      hFileName=GlobalAlloc(GHND,128); 
  97.      hExtension=GlobalAlloc(GHND,128); 
  98.      hNewFile=GlobalAlloc(GHND,128);
  99.      hEntry=GlobalAlloc(GHND,20);
  100.      hAlias=GlobalAlloc(GHND,10);
  101.      hExeName=GlobalAlloc(GHND,10);
  102.  
  103.      if (hBuffer && hSection && hFileName && hEntry && hExtension)
  104.       {
  105.        lpBuffer=GlobalLock(hBuffer);
  106.        lpSection=GlobalLock(hSection);
  107.        lpFileName=GlobalLock(hFileName); 
  108.        lpExtension=GlobalLock(hExtension); 
  109.        lpNewFile=GlobalLock(hNewFile);
  110.        lpEntry=GlobalLock(hEntry);
  111.        lpAlias=GlobalLock(hAlias);
  112.        lpExeName=GlobalLock(hExeName);
  113.  
  114.        if (lpBuffer && lpSection && lpFileName && lpEntry && lpAlias && lpExtension)
  115.            {  
  116.            
  117.            // get the executable name and directory.
  118.            
  119.         nBytes=GetModuleFileName(GetModuleHandle("playvfw.exe"),lpExtension,128);
  120.         if(nBytes)
  121.              {
  122.              
  123.              // look for the section Button# in the ini file.
  124.              
  125.               wsprintf(lpSection,"Button%d",nButton);        
  126.               
  127.               // seperate the extension from the exename.
  128.               
  129.               ExtractExtension(lpExtension,lpExeName);   
  130.               
  131.               // copy the extension into the filename.
  132.               
  133.               lstrcpy(lpFileName,lpExtension); 
  134.               
  135.                                                       
  136.                // check to see if the screen resolution is 640 X 480 if so look in the lowres directory.                                       
  137.                                                       
  138.                //if (GetSystemMetrics(SM_CXSCREEN)==640)
  139.                if(!fHiResCapable())
  140.                       lstrcat(lpFileName,"lowres\\");   
  141.                         
  142.               lstrcat(lpFileName,lpExeName);
  143.               
  144.               // add the filename and the extension of ini (i.e. playvfw.ini).
  145.               
  146.               lstrcat(lpFileName,".ini"); 
  147.               
  148.               // if it is button 7 (the initial screen button) see if we need to grab a random number.  If
  149.               // so lets grab the random # and continue.
  150.               
  151.               if (nButton==7)
  152.                     {   
  153.                      lstrcpy(lpEntry,"Rand");
  154.               
  155.                      nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  156.                      if(!nSize)
  157.                          {
  158.                           ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  159.                           return FALSE;
  160.                           }
  161.  
  162.                    StripSpaces(lpBuffer);
  163.                    
  164.                    if(!lstrcmp(lpBuffer,"TRUE"))
  165.                         {
  166.                          nAviFile=GetRandNumber123();     
  167.                          nAudioFile=GetRandNumber123();
  168.                          }
  169.                    else
  170.                         {
  171.                          nAviFile=1;
  172.                          nAudioFile=1;
  173.                         }                     
  174.                     }
  175.               else
  176.                     {     
  177.                      nAviFile=1;      
  178.                      nAudioFile=1;                    
  179.                     }
  180.               
  181.               // look at the AVI entry and grab the file name.
  182.                     
  183.               wsprintf(lpEntry,"AVI File%d",nAviFile);
  184.               nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  185.               if(!nSize)
  186.                 {
  187.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  188.                 return FALSE;
  189.                 }
  190.  
  191.               StripSpaces(lpBuffer);
  192.               
  193.               // if we need to add on an additional AVI subdirectory due to the AVI directory entry do it.
  194.               
  195.               if (lstrlen(lpDirs->szAviDir))
  196.                    {
  197.                     lstrcpy(lpNewFile,lpExtension);
  198.                     lstrcat(lpNewFile,lpDirs->szAviDir);
  199.                     lstrcat(lpNewFile,"\\");
  200.                     lstrcat(lpNewFile,lpBuffer);
  201.                     }
  202.               else
  203.                    lstrcpy(lpNewFile,lpBuffer); 
  204.                    
  205.               // need an alias to distinguish between the different AVI files.          
  206.               
  207.               wsprintf(lpAlias,"foo%d",nButton);
  208.  
  209.               // open the AVI file.
  210.               
  211.               lpDevice->wDeviceID = OpenVFWFile(hWndMain,wGlobalDeviceID,(LPSTR)lpNewFile,lpAlias);
  212.  
  213.                if (!lpDevice->wDeviceID)
  214.                 {
  215.                 ReturnDeviceError(lpBuffer,hFileName,hSection,hBuffer,hExeName,hAlias);
  216.                 return FALSE;
  217.                 }
  218.                
  219.                
  220.                // get the wave file.
  221.                
  222.                wsprintf(lpEntry,"Audio File%d",nAudioFile);
  223.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  224.  
  225.                if(!nSize)
  226.                 {
  227.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  228.                 return FALSE;
  229.                 }
  230.  
  231.                StripSpaces(lpBuffer);
  232.                
  233.                // we need to get an alias to distinguish this from other wave files.
  234.  
  235.                wsprintf(lpAlias,"oof%d",nButton); 
  236.                
  237.                // add the wave sub directory if there is one.
  238.                
  239.               if (lstrlen(lpDirs->szWavDir))
  240.                    {
  241.                     lstrcpy(lpNewFile,lpExtension);
  242.                     lstrcat(lpNewFile,lpDirs->szWavDir);
  243.                     lstrcat(lpNewFile,"\\");
  244.                     lstrcat(lpNewFile,lpBuffer);
  245.                     }
  246.               else
  247.                    lstrcpy(lpNewFile,lpBuffer);     
  248.  
  249.               // if the sound device wasn't loaded don't open the wave file.  If they specified in the ini
  250.               // file to have no wave playback then don't do this either.  Otherwise play the wave file. 
  251.  
  252.                if (!bNoSound)
  253.                     {
  254.                      lpDevice->wAudioDeviceID = OpenWaveFile(wGlobalAudioDeviceID,lpNewFile,lpAlias);
  255.  
  256.                      if (!lpDevice->wAudioDeviceID)
  257.                            {
  258.                             ReturnDeviceError(lpBuffer,hFileName,hSection,hBuffer,hExeName,hAlias);
  259.                             return FALSE;
  260.                            }
  261.                      }
  262.                 
  263.                // grab the position information regarding the button. 
  264.                      
  265.                wsprintf(lpEntry,"Position%d",nAviFile);
  266.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  267.                if(!nSize)
  268.                 {
  269.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  270.                 return FALSE;
  271.                 }
  272.  
  273.                StripSpaces(lpBuffer);
  274.                ReturnCoor(lpBuffer,lpPoints);
  275.                
  276.                
  277.                // Should this button be animated?
  278.                
  279.                lstrcpy(lpEntry,"Animation");
  280.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  281.  
  282.                if(!nSize)
  283.                 {
  284.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  285.                 return FALSE;
  286.                 }
  287.  
  288.                StripSpaces(lpBuffer);
  289.  
  290.                if(!lstrcmp(lpBuffer,"disabled"))
  291.                 lpDevice->bPlayVideo=FALSE;
  292.                else
  293.                 lpDevice->bPlayVideo=TRUE;
  294.                
  295.                // should the wave file play for this button?
  296.                
  297.                lstrcpy(lpEntry,"Audio");
  298.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  299.                if(!nSize)
  300.                 {
  301.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  302.                 return FALSE;
  303.                 }
  304.  
  305.                StripSpaces(lpBuffer);
  306.  
  307.                if(!lstrcmp(lpBuffer,"disabled"))
  308.                 lpDevice->bPlayAudio=FALSE;
  309.                else
  310.                 lpDevice->bPlayAudio=TRUE;  
  311.                 
  312.                // if the system has no sound then kill the sound even though it may be enabled in the ini file.                                 
  313.                                                 
  314.                if (bNoSound)
  315.                      lpDevice->bPlayAudio=FALSE;     
  316.                 
  317.              } // End if nBytes
  318.         } // End of if the memory locks succeded.
  319.       else
  320.            {
  321.            MessageBox(hWndMain,"Profile string Memory lock failed","ERROR",MB_OK);
  322.            }
  323.       } // End of if the memory allocations succeded.
  324.      else
  325.       MessageBox(hWndMain,"Memory allocation failed for profile strings","ERROR",MB_OK);
  326.  
  327.  
  328.     GlobalUnlock(hFileName);
  329.     GlobalUnlock(hSection);
  330.     GlobalUnlock(hBuffer);
  331.     GlobalUnlock(hEntry);
  332.     GlobalUnlock(hAlias);
  333.     GlobalUnlock(hExeName);
  334.  
  335.     GlobalFree(hFileName);
  336.     GlobalFree(hSection);
  337.     GlobalFree(hBuffer);
  338.     GlobalFree(hEntry);
  339.     GlobalFree(hAlias);
  340.     GlobalFree(hExeName);
  341.  
  342. return TRUE;
  343. }
  344.  
  345. /****************************************************************************
  346.  
  347.     FUNCTION    : GetPG2FromIni(LPDEVICESTRUCT,int,LPRECT,LPSTR)
  348.  
  349.     PURPOSE   : This function retrieves the information for the last page.  It also closes and 
  350.                  re-opens the wave and video files to conserve on resources.
  351.     
  352.     COMMENTS  : 
  353.  
  354.     HISTORY   : Created by Steven Molstad 8/1/93
  355.  
  356. ****************************************************************************/ 
  357.  
  358. BOOL FAR PASCAL GetPG2FromIni(lpDevice,nButton,lpPoints,lpIniName)
  359. LPDEVICESTRUCT lpDevice;
  360. int nButton;
  361. LPRECT lpPoints;
  362. LPSTR lpIniName;
  363. {
  364.      HANDLE hBuffer;
  365.      LPSTR lpBuffer;
  366.  
  367.      HANDLE hSection;
  368.      LPSTR lpSection;
  369.  
  370.      HANDLE hFileName;
  371.      LPSTR lpFileName;
  372.  
  373.      HANDLE hEntry;
  374.      LPSTR lpEntry;
  375.  
  376.      HANDLE hAlias;
  377.      LPSTR  lpAlias;
  378.  
  379.      HANDLE hExeName;
  380.      LPSTR lpExeName;
  381.      
  382.      HANDLE hExtension;
  383.      LPSTR lpExtension;  
  384.      
  385.      HANDLE hNewFile;
  386.      LPSTR lpNewFile;
  387.      
  388.      int  nSize;
  389.      int nBytes;
  390.      int nAviFile;
  391.      int nAudioFile;
  392.     
  393.      BOOL bReturn;
  394.  
  395.     
  396.            
  397.      hBuffer=GlobalAlloc(GHND,80);
  398.      hSection=GlobalAlloc(GHND,10);
  399.      hFileName=GlobalAlloc(GHND,128);
  400.      hExtension=GlobalAlloc(GHND,128); 
  401.      hNewFile=GlobalAlloc(GHND,128);
  402.      hEntry=GlobalAlloc(GHND,20);
  403.      hAlias=GlobalAlloc(GHND,20);
  404.      hExeName=GlobalAlloc(GHND,10);
  405.  
  406.      if (hBuffer && hSection && hFileName && hEntry && hExtension && hNewFile)
  407.       {
  408.        lpBuffer=GlobalLock(hBuffer);
  409.        lpSection=GlobalLock(hSection);
  410.        lpFileName=GlobalLock(hFileName);
  411.        lpExtension=GlobalLock(hExtension); 
  412.        lpNewFile=GlobalLock(hNewFile);
  413.        lpEntry=GlobalLock(hEntry);
  414.        lpAlias=GlobalLock(hAlias);
  415.        lpExeName=GlobalLock(hExeName);
  416.  
  417.        if (lpBuffer && lpSection && lpFileName && lpEntry && lpAlias && lpExtension && hNewFile)
  418.            {
  419.         nBytes=GetModuleFileName(GetModuleHandle("playvfw.exe"),lpExtension,128);
  420.         if(nBytes)
  421.              {
  422.               wsprintf(lpSection,"Button%d",nButton);
  423.               ExtractExtension(lpExtension,lpExeName);   
  424.               lstrcpy(lpFileName,lpExtension);
  425.               
  426.               if (lstrlen(lpDirs->szIniDir))  
  427.                    {   
  428.                    
  429.                    lstrcat(lpFileName,lpDirs->szIniDir);
  430.                    lstrcat(lpFileName,"\\"); 
  431.                    
  432.                    //if (GetSystemMetrics(SM_CXSCREEN)==640) 
  433.                    if(!fHiResCapable())
  434.                         lstrcat(lpFileName,"lowres\\");
  435.                    
  436.                    }
  437.               
  438.                 
  439.                    
  440.               lstrcat(lpFileName,lpIniName);
  441.             
  442.               lstrcat(lpFileName,".ini"); 
  443.               
  444.               // special code if this is the morph window.  Since the morph window can pick from 3 different
  445.               // AVI files.
  446.               
  447.              if(!lstrcmp(lpIniName,"morph"))
  448.                   {    
  449.                     lstrcpy(lpEntry,"Rand");
  450.               
  451.                     nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  452.                     if(!nSize)
  453.                          {
  454.                           ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  455.                           return FALSE;
  456.                           }
  457.  
  458.                    StripSpaces(lpBuffer);
  459.                    
  460.                    if(!lstrcmp(lpBuffer,"TRUE"))
  461.                         {
  462.                          nAviFile=GetRandNumber123();     
  463.                          nAudioFile=GetRandNumber123();
  464.                          }
  465.                    else
  466.                         {
  467.                          nAviFile=1;
  468.                          nAudioFile=1;
  469.                         }    
  470.                   }      
  471.              else
  472.                   {
  473.                    nAviFile=1;
  474.                    nAudioFile=1;
  475.                   }
  476.                    
  477.               wsprintf(lpEntry,"AVI File%d",nAviFile);
  478.               nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  479.               if(!nSize)
  480.                 {
  481.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  482.                 return FALSE;
  483.                 }
  484.  
  485.               StripSpaces(lpBuffer);
  486.  
  487.               if(!lstrcmp(lpIniName,"morph"))
  488.                wsprintf(lpAlias,"for%d",nButton);
  489.               else
  490.                wsprintf(lpAlias,"%s%d",lpIniName,nButton);
  491.                
  492.                if (lstrlen(lpDirs->szAviDir))
  493.                    {
  494.                     lstrcpy(lpNewFile,lpExtension);
  495.                     lstrcat(lpNewFile,lpDirs->szAviDir);
  496.                     lstrcat(lpNewFile,"\\");     
  497.                     
  498.                     //if (GetSystemMetrics(SM_CXSCREEN)==640) 
  499.                     if(!fHiResCapable())
  500.                         lstrcat(lpNewFile,"lowres\\");   
  501.                         
  502.                     lstrcat(lpNewFile,lpBuffer);
  503.                     }
  504.               else
  505.                    lstrcpy(lpNewFile,lpBuffer);  
  506.                
  507.               
  508.               if(lpDevice->wDeviceID)
  509.                {
  510.               
  511.  
  512.                 bReturn = CloseVFWFile(lpDevice->wDeviceID);
  513.                }
  514.                      
  515.               
  516.                lpDevice->wDeviceID = OpenVFWFile(hWndMain,wGlobalDeviceID,(LPSTR)lpNewFile,lpAlias);
  517.  
  518.                if (!lpDevice->wDeviceID)
  519.                      {
  520.                       ReturnDeviceError(lpBuffer,hFileName,hSection,hBuffer,hExeName,hAlias);
  521.                       return FALSE;
  522.                      }
  523.                      
  524.                      
  525.                wsprintf(lpEntry,"Audio File%d",nAudioFile);
  526.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  527.  
  528.                if(!nSize)
  529.                 {
  530.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  531.                 return FALSE;
  532.                 }
  533.  
  534.                StripSpaces(lpBuffer);  
  535.                
  536.                 if (lstrlen(lpDirs->szWavDir))
  537.                    {
  538.                     lstrcpy(lpNewFile,lpExtension);
  539.                     lstrcat(lpNewFile,lpDirs->szWavDir);
  540.                     lstrcat(lpNewFile,"\\");                  
  541.                     lstrcat(lpNewFile,lpBuffer);
  542.                     }
  543.               else
  544.                    lstrcpy(lpNewFile,lpBuffer);  
  545.                    
  546.                
  547.                if(!lstrcmp(lpIniName,"morph"))
  548.                  wsprintf(lpAlias,"%s%d",lpIniName,nButton);
  549.                else
  550.                  wsprintf(lpAlias,"oof%d",nButton);
  551.  
  552.               
  553.                if (!bNoSound)
  554.                     { 
  555.                     
  556.                      if(lpDevice->wAudioDeviceID)
  557.                           {
  558.                 
  559.                            bReturn = CloseWaveFile(lpDevice->wAudioDeviceID);
  560.                           }
  561.  
  562.                      lpDevice->wAudioDeviceID = OpenWaveFile(wGlobalAudioDeviceID,lpNewFile,lpAlias);
  563.  
  564.                      if (!lpDevice->wAudioDeviceID)
  565.                           {
  566.                            ReturnDeviceError(lpBuffer,hFileName,hSection,hBuffer,hExeName,hAlias);
  567.                            return FALSE;
  568.                           }
  569.                      }    
  570.                      
  571.                wsprintf(lpEntry,"Position%d",nAviFile);
  572.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  573.                if(!nSize)
  574.                 {
  575.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  576.                 return FALSE;
  577.                 }
  578.  
  579.                StripSpaces(lpBuffer);
  580.                ReturnCoor(lpBuffer,lpPoints);
  581.  
  582.                lstrcpy(lpEntry,"Animation");
  583.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  584.  
  585.                if(!nSize)
  586.                 {
  587.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  588.                 return FALSE;
  589.                 }
  590.  
  591.                StripSpaces(lpBuffer);
  592.  
  593.                if(!lstrcmp(lpBuffer,"disabled"))
  594.                 lpDevice->bPlayVideo=FALSE;
  595.                else
  596.                 lpDevice->bPlayVideo=TRUE;
  597.  
  598.                lstrcpy(lpEntry,"Audio");
  599.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  600.                if(!nSize)
  601.                 {
  602.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  603.                 return FALSE;
  604.                 }
  605.  
  606.                StripSpaces(lpBuffer);
  607.  
  608.                if(!lstrcmp(lpBuffer,"disabled"))
  609.                 lpDevice->bPlayAudio=FALSE;
  610.                else
  611.                 lpDevice->bPlayAudio=TRUE;
  612.                                                 
  613.                // if the system has no sound then kill the sound even though it may be enabled in the ini file.                                 
  614.                                                 
  615.                if (bNoSound)
  616.                      lpDevice->bPlayAudio=FALSE;     
  617.                     
  618.                     
  619.                if(lstrcmp(lpIniName,"morph"))
  620.                     {
  621.                      lstrcpy(lpEntry,"FileName");
  622.  
  623.                      nSize=GetPrivateProfileString(lpSection,lpEntry,"",(LPSTR)lpDevice->szFileName,24,lpFileName);
  624.                      if(!nSize)
  625.                           {
  626.                            lstrcpy(lpBuffer,lpDevice->szFileName);
  627.                            ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  628.                            return FALSE;
  629.                            }
  630.  
  631.                       //StripSpaces((LPSTR)lpDevice->szFileName);
  632.                      }
  633.               //lstrcpy(lpDevice->FileName,lpBuffer);
  634.  
  635.              } // End if nBytes
  636.         } // End of if the memory locks succeded.
  637.       else
  638.            {
  639.            MessageBox(hWndMain,"Profile string Memory lock failed","ERROR",MB_OK);
  640.            }
  641.       } // End of if the memory allocations succeded.
  642.      else
  643.       MessageBox(hWndMain,"Memory allocation failed for profile strings","ERROR",MB_OK);
  644.  
  645.  
  646.     GlobalUnlock(hFileName);
  647.     GlobalUnlock(hSection);
  648.     GlobalUnlock(hBuffer);
  649.     GlobalUnlock(hEntry);
  650.     GlobalUnlock(hAlias);
  651.     GlobalUnlock(hExeName);
  652.  
  653.     GlobalFree(hFileName);
  654.     GlobalFree(hSection);
  655.     GlobalFree(hBuffer);
  656.     GlobalFree(hEntry);
  657.     GlobalFree(hAlias);
  658.     GlobalFree(hExeName);
  659.  
  660. return TRUE;
  661. }
  662.  
  663. /****************************************************************************
  664.  
  665.     FUNCTION    : ReturnProfileError(LPSTR ,LPSTR ,LPSTR ,HANDLE ,HANDLE ,HANDLE ,HANDLE ,HANDLE )
  666.  
  667.     PURPOSE   :   This function returns an error if it can't find the entry or section in the ini file.
  668.     
  669.     COMMENTS  : 
  670.  
  671.     HISTORY   :   Created by Steven Molstad 8/15/93
  672.  
  673. ****************************************************************************/ 
  674.  
  675.  
  676. void FAR PASCAL ReturnProfileError(LPSTR lpEntry,LPSTR lpSection,LPSTR lpFileName,HANDLE hFileName,HANDLE hSection,HANDLE hBuffer,HANDLE hExeName,HANDLE hAlias)
  677. {
  678.  
  679.      HANDLE hBuf;
  680.      LPSTR lpBuf;
  681.  
  682.      hBuf=GlobalAlloc(GHND,255);
  683.      if(!hBuf)
  684.       return;
  685.  
  686.      lpBuf=GlobalLock(hBuf);
  687.  
  688.      if (!lpBuf)
  689.      return;
  690.  
  691.      wsprintf(lpBuf,"The %s entry for %s was omitted in the %s file.  Please edit the ini file.",lpEntry,lpSection,lpFileName);
  692.      MessageBox(hWndMain,lpBuf,"ERROR",MB_OK);
  693.  
  694.      GlobalUnlock(hFileName);
  695.      GlobalUnlock(hSection);
  696.      GlobalUnlock(hBuffer);
  697.      GlobalUnlock(hExeName);
  698.      GlobalUnlock(hAlias);
  699.      GlobalUnlock(hBuf);
  700.  
  701.      GlobalFree(hFileName);
  702.      GlobalFree(hSection);
  703.      GlobalFree(hBuffer);
  704.      GlobalFree(hExeName);
  705.      GlobalFree(hAlias);
  706.      GlobalFree(hBuf);
  707.  
  708.      return;
  709. }  
  710.  
  711. /****************************************************************************
  712.  
  713.     FUNCTION    : GetVidWinFromIni(LPDEVICESTRUCT,int,LPRECT,LPRECT,LPRECT,LPSTR)
  714.  
  715.     PURPOSE   :   This function retrieves the information for the Video Window on the last page.
  716.     
  717.     COMMENTS  : 
  718.  
  719.     HISTORY   : Created by Steven Molstad 8/1/93
  720.  
  721. ****************************************************************************/ 
  722.  
  723. BOOL FAR PASCAL GetVidWinFromIni(lpDevice,nButton,lpPoints,lpPoints2,lpPoints3,lpIniName)
  724. LPDEVICESTRUCT lpDevice;
  725. int nButton;
  726. LPRECT lpPoints;
  727. LPRECT lpPoints2; 
  728. LPRECT lpPoints3;
  729. LPSTR lpIniName;
  730. {
  731.      HANDLE hBuffer;
  732.      LPSTR lpBuffer;
  733.  
  734.      HANDLE hSection;
  735.      LPSTR lpSection;
  736.  
  737.      HANDLE hFileName;
  738.      LPSTR lpFileName;
  739.  
  740.      HANDLE hEntry;
  741.      LPSTR lpEntry;
  742.  
  743.      HANDLE hAlias;
  744.      LPSTR  lpAlias;
  745.  
  746.      HANDLE hExeName;
  747.      LPSTR lpExeName; 
  748.      
  749.      HANDLE hExtension;
  750.      LPSTR lpExtension;  
  751.      
  752.      HANDLE hNewFile;
  753.      LPSTR lpNewFile;
  754.  
  755.      int  nSize;
  756.      int nBytes;
  757.      int nAviFile;
  758.      int nAudioFile;
  759.      
  760.      //BOOL bReturn;
  761.  
  762.      
  763.      //nAviFile=GetRandNumber123(); 
  764.      nAviFile=1;
  765.      //nAudioFile=GetRandNumber123();
  766.      nAudioFile=1;
  767.  
  768.      hBuffer=GlobalAlloc(GHND,80);
  769.      hSection=GlobalAlloc(GHND,10);
  770.      hFileName=GlobalAlloc(GHND,128);
  771.      hExtension=GlobalAlloc(GHND,128);
  772.      hNewFile=GlobalAlloc(GHND,128);
  773.      hEntry=GlobalAlloc(GHND,20);
  774.      hAlias=GlobalAlloc(GHND,20);
  775.      hExeName=GlobalAlloc(GHND,10);
  776.  
  777.      if (hBuffer && hSection && hFileName && hEntry && hExtension && hNewFile)
  778.       {
  779.        lpBuffer=GlobalLock(hBuffer);
  780.        lpSection=GlobalLock(hSection);
  781.        lpFileName=GlobalLock(hFileName);
  782.        lpExtension=GlobalLock(hExtension);
  783.        lpNewFile=GlobalLock(hNewFile);
  784.        lpEntry=GlobalLock(hEntry);
  785.        lpAlias=GlobalLock(hAlias);
  786.        lpExeName=GlobalLock(hExeName);
  787.  
  788.        if (lpBuffer && lpSection && lpFileName && lpEntry && lpAlias && lpExtension && lpNewFile)
  789.            {
  790.         nBytes=GetModuleFileName(GetModuleHandle("playvfw.exe"),lpExtension,128);
  791.         if(nBytes)
  792.              {
  793.               wsprintf(lpSection,"Button%d",nButton);
  794.               ExtractExtension(lpExtension,lpExeName); 
  795.               lstrcpy(lpFileName,lpExtension);
  796.               
  797.                 if (lstrlen(lpDirs->szIniDir))  
  798.                    {
  799.                    lstrcat(lpFileName,lpDirs->szIniDir);
  800.                    lstrcat(lpFileName,"\\");
  801.                    
  802.                    //if (GetSystemMetrics(SM_CXSCREEN)==640)
  803.                    if(!fHiResCapable())
  804.                         lstrcat(lpFileName,"lowres\\");
  805.                    }       
  806.                    
  807.               lstrcat(lpFileName,lpIniName);
  808.               // put in check for a exe file already 8 characters long.
  809.               //lstrcat(lpFileName,"2");
  810.               lstrcat(lpFileName,".ini");
  811.  
  812.               wsprintf(lpEntry,"AVI File");
  813.               nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  814.               if(!nSize)
  815.                 {
  816.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  817.                 return FALSE;
  818.                 }
  819.  
  820.               StripSpaces(lpBuffer);  
  821.               
  822.               if (lstrlen(lpDirs->szAviDir))
  823.                    {
  824.                     lstrcpy(lpNewFile,lpExtension);
  825.                     lstrcat(lpNewFile,lpDirs->szAviDir);
  826.                     lstrcat(lpNewFile,"\\");       
  827.                     
  828.                     //if (GetSystemMetrics(SM_CXSCREEN)==640) 
  829.                     if(!fHiResCapable())
  830.                         lstrcat(lpNewFile,"lowres\\"); 
  831.                         
  832.                     lstrcat(lpNewFile,lpBuffer);
  833.                     }
  834.               else
  835.                    lstrcpy(lpNewFile,lpBuffer);  
  836.               
  837.               wsprintf(lpAlias,"VidWin%d",nButton);
  838.  
  839.              
  840.  
  841.               lpDevice->wDeviceID = OpenVFWFile(hWndMain,wGlobalDeviceID,(LPSTR)lpNewFile,lpAlias);
  842.  
  843.                if (!lpDevice->wDeviceID)
  844.                 {
  845.                 ReturnDeviceError(lpBuffer,hFileName,hSection,hBuffer,hExeName,hAlias);
  846.                 return FALSE;
  847.                 }
  848.  
  849.               
  850.  
  851.                wsprintf(lpEntry,"Position");
  852.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  853.                if(!nSize)
  854.                 {
  855.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  856.                 return FALSE;
  857.                 }
  858.  
  859.                StripSpaces(lpBuffer);
  860.                ReturnCoor(lpBuffer,lpPoints);
  861.  
  862.                lstrcpy(lpEntry,"ControlPos");
  863.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  864.                if(!nSize)
  865.                 {
  866.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  867.                 return FALSE;
  868.                 }
  869.  
  870.                StripSpaces(lpBuffer);
  871.                ReturnCoor(lpBuffer,lpPoints2);
  872.                
  873.                  wsprintf(lpEntry,"EditPosition");
  874.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  875.                if(!nSize)
  876.                 {
  877.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  878.                 return FALSE;
  879.                 }
  880.  
  881.                StripSpaces(lpBuffer);
  882.                ReturnCoor(lpBuffer,lpPoints3);
  883.                
  884.              } // End if nBytes
  885.         } // End of if the memory locks succeded.
  886.       else
  887.            {
  888.            MessageBox(hWndMain,"Profile string Memory lock failed","ERROR",MB_OK);
  889.            }
  890.       } // End of if the memory allocations succeded.
  891.      else
  892.       MessageBox(hWndMain,"Memory allocation failed for profile strings","ERROR",MB_OK);
  893.  
  894.  
  895.     GlobalUnlock(hFileName);
  896.     GlobalUnlock(hSection);
  897.     GlobalUnlock(hBuffer);
  898.     GlobalUnlock(hEntry);
  899.     GlobalUnlock(hAlias);
  900.     GlobalUnlock(hExeName);
  901.  
  902.     GlobalFree(hFileName);
  903.     GlobalFree(hSection);
  904.     GlobalFree(hBuffer);
  905.     GlobalFree(hEntry);
  906.     GlobalFree(hAlias);
  907.     GlobalFree(hExeName);
  908.  
  909. return TRUE;
  910. }
  911.  
  912. /****************************************************************************
  913.  
  914.     FUNCTION    : GetDirFromIni(LPDIRSTRUCT,LPSTR)
  915.  
  916.     PURPOSE   :  This function gets the directory entries in the ini file.
  917.     
  918.     COMMENTS  : 
  919.  
  920.     HISTORY   : Created by Steven Molstad 8/1/93.
  921.  
  922. ****************************************************************************/  
  923.  
  924. BOOL FAR PASCAL GetDirFromIni(lpDirs,lpIniName)
  925. LPDIRSTRUCT lpDirs;
  926. LPSTR lpIniName;
  927. {
  928.      HANDLE hBuffer;
  929.      LPSTR lpBuffer;
  930.  
  931.      HANDLE hSection;
  932.      LPSTR lpSection;
  933.  
  934.      HANDLE hFileName;
  935.      LPSTR lpFileName;
  936.  
  937.      HANDLE hEntry;
  938.      LPSTR lpEntry;
  939.  
  940.      HANDLE hAlias;
  941.      LPSTR  lpAlias;
  942.  
  943.      HANDLE hExeName;
  944.      LPSTR lpExeName;
  945.  
  946.      int  nSize;
  947.      int nBytes;
  948.      int nAviFile;
  949.      int nAudioFile;
  950.   
  951.      //BOOL bReturn; 
  952.      
  953.  
  954.      
  955.      nAviFile=GetRandNumber123(); 
  956.      nAviFile=1;
  957.      nAudioFile=GetRandNumber123();
  958.      nAudioFile=1;
  959.      
  960.      hBuffer=GlobalAlloc(GHND,80);
  961.      hSection=GlobalAlloc(GHND,10);
  962.      hFileName=GlobalAlloc(GHND,128);
  963.      hEntry=GlobalAlloc(GHND,20);
  964.      hAlias=GlobalAlloc(GHND,20);
  965.      hExeName=GlobalAlloc(GHND,10);
  966.  
  967.      if (hBuffer && hSection && hFileName && hEntry)
  968.       {
  969.        lpBuffer=GlobalLock(hBuffer);
  970.        lpSection=GlobalLock(hSection);
  971.        lpFileName=GlobalLock(hFileName);
  972.        lpEntry=GlobalLock(hEntry);
  973.        lpAlias=GlobalLock(hAlias);
  974.        lpExeName=GlobalLock(hExeName);
  975.  
  976.        if (lpBuffer && lpSection && lpFileName && lpEntry && lpAlias)
  977.            {
  978.         nBytes=GetModuleFileName(GetModuleHandle("playvfw.exe"),lpFileName,128);
  979.         if(nBytes)
  980.              {
  981.               lstrcpy(lpSection,"FILES");
  982.               ExtractExtension(lpFileName,lpExeName);
  983.                
  984.               //if (GetSystemMetrics(SM_CXSCREEN)==640)
  985.               if(!fHiResCapable())
  986.                         lstrcat(lpFileName,"lowres\\");
  987.                         
  988.               lstrcat(lpFileName,lpIniName);
  989.               // put in check for a exe file already 8 characters long.
  990.               //lstrcat(lpFileName,"2");
  991.               lstrcat(lpFileName,".ini");
  992.  
  993.               lstrcpy(lpEntry,"AVI");
  994.               nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  995.               if(!nSize)
  996.                 {
  997.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  998.                 return FALSE;
  999.                 }
  1000.  
  1001.               StripSpaces(lpBuffer);
  1002.  
  1003.               
  1004.                         
  1005.               lstrcpy(lpDirs->szAviDir,lpBuffer);
  1006.  
  1007.               
  1008.  
  1009.                lstrcpy(lpEntry,"INI"); 
  1010.                
  1011.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  1012.                if(!nSize)
  1013.                 {
  1014.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  1015.                 return FALSE;
  1016.                 }       
  1017.                 
  1018.               
  1019.                         
  1020.                lstrcpy(lpDirs->szIniDir,lpBuffer);
  1021.                
  1022.                lstrcpy(lpEntry,"WAV");  
  1023.                
  1024.                nSize=GetPrivateProfileString(lpSection,lpEntry,"",lpBuffer,80,lpFileName);
  1025.                if(!nSize)
  1026.                 {
  1027.                 ReturnProfileError(lpEntry,lpSection,lpFileName,hFileName,hSection,hBuffer,hExeName,hAlias);
  1028.                 return FALSE;
  1029.                 }
  1030.  
  1031.                
  1032.                 lstrcpy(lpDirs->szWavDir,lpBuffer);
  1033.  
  1034.              } // End if nBytes
  1035.         } // End of if the memory locks succeded.
  1036.       else
  1037.            {
  1038.            MessageBox(hWndMain,"Profile string Memory lock failed","ERROR",MB_OK);
  1039.            }
  1040.       } // End of if the memory allocations succeded.
  1041.      else
  1042.       MessageBox(hWndMain,"Memory allocation failed for profile strings","ERROR",MB_OK);
  1043.  
  1044.  
  1045.     GlobalUnlock(hFileName);
  1046.     GlobalUnlock(hSection);
  1047.     GlobalUnlock(hBuffer);
  1048.     GlobalUnlock(hEntry);
  1049.     GlobalUnlock(hAlias);
  1050.     GlobalUnlock(hExeName);
  1051.  
  1052.     GlobalFree(hFileName);
  1053.     GlobalFree(hSection);
  1054.     GlobalFree(hBuffer);
  1055.     GlobalFree(hEntry);
  1056.     GlobalFree(hAlias);
  1057.     GlobalFree(hExeName);
  1058.  
  1059. return TRUE;
  1060. }
  1061.  
  1062.